use local_ip_address::local_ip;
use std::fs;

#[tauri::command]
pub fn read_file(path: &str) -> String {
    fs::read_to_string(path).unwrap_or_else(|_| panic!("无法读取文件：{}", path))
}

#[tauri::command]
pub fn write_file(path: &str, content: &str) {
    fs::write(path, content).unwrap_or_else(|_| panic!("无法写入文件：{}", path))
}

#[tauri::command]
pub fn delete_file(path: &str) {
    fs::remove_file(path).unwrap_or_else(|_| panic!("无法删除文件：{}", path))
}

#[tauri::command]
pub fn get_ip() -> String {
    let address = local_ip();
    if let Ok(address) = address {
        address.to_string()
    } else {
        "127.0.0.1".to_string()
    }
}
